/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.dusin.teachassistdbservice.dao4mysql;

import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.dusin.teachassistdbservice.dao.TeacherDao;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 *
 * @author dusin
 */
public class TeacherDaoImpl implements TeacherDao{
    static Logger logger = Logger.getLogger(TeacherDaoImpl.class);
    private JdbcTemplate jdbcTemplate;

    public TeacherDaoImpl(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
    
    
    @Override
    public boolean doCreate(Object[] bean) {
        boolean flag = true;
        String sql = null;
        sql = "insert into teacher(teacherno,name,password,level) values(?,?,?,?)";
        int rows = jdbcTemplate.update(sql, bean); 
        if (rows <= 0) {
            flag = false;
        }
        return flag;
    }

    @Override
    public boolean doDeleteByNo(String no) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public boolean doUpdate(Object[] bean) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

     @Override
    public Map<String,Object> login(String username,String password){
        boolean flag = true;
        String sql = null;
        sql = "select * from  teacher where teacherno = ?  and password=?";
        return jdbcTemplate.queryForMap(sql,username,password);        
    }
    
    @Override
    public Map<String, Object> findByNo(String no) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<Map<String, Object>> findAll() {
        String sql = "select * from student";
        return jdbcTemplate.queryForList(sql);
    }

    
    
    @Override
    public List<Map<String, Object>> findAll(int start, int size) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
